package rsync

import (
	"JudgeClient/global"
	"bytes"
	"os"
	"os/exec"
	"path/filepath"
)

func SyncSingle(testCaseId string) (err error) {
	remote := os.Getenv("RSYNC_USER") + "@" + os.Getenv("RSYNC_HOST")
	rsyncPwd := filepath.Join(global.Conf.Path.TestCaseDir, "rsyncd.passwd")
	rsyncCmd := `rsync -av --password-file ` + rsyncPwd + ` --include="*.in" --include="*.out"  --include="*/"  --exclude="*" --delete ` + remote + `::testcases/` + testCaseId + ` ` + global.Conf.Path.TestCaseDir
	in := bytes.NewBuffer(nil)
	cmd := exec.Command("/bin/bash")
	cmd.Stdin = in
	in.WriteString(rsyncCmd)
	err = cmd.Run()
	return
}
